package com.travel.controller;


import com.qianfeng.util.ResultMsg;
import com.travel.entity.TbCart;
import com.travel.entity.TbTrain;
import com.travel.service.TrainService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admintrain")
@Api(value = "火车票购买",description = "后台火车票")
public class AdminTrainController {
    @Autowired
    TrainService trainService;

    @GetMapping("/findall")
    public ResultMsg selectAll(@RequestParam(required = false,defaultValue = "1") int current, @RequestParam(required = false,defaultValue = "4") int size){
        return trainService.selectAll(current,size);
    }

    @GetMapping("/order")
    public ResultMsg trainOrder( String trainId){
        return trainService.trainOrder(trainId);
    }

    @GetMapping("/deleteone")
    public ResultMsg deleteOne(String tid){
        return trainService.deleteOneByTid(tid);
    }

    @GetMapping("/update")
    public ResultMsg updateOne(TbTrain tbTrain){
        return trainService.updateOne(tbTrain);
    }




    @GetMapping("/getTrainById/{trainId}")
    public ResultMsg getTrainById(@PathVariable("trainId") String trainId){
        return trainService.getTrainById(trainId);
    }

    @PostMapping("/updateTrain")
    public ResultMsg updateTrain(@RequestBody TbTrain tbTrain){
        return trainService.updateTrain(tbTrain);
    }

    @GetMapping("/deleteTrain/{id}")
    public ResultMsg deleteTrain(@PathVariable("id") String id){
        return trainService.deleteTrain(id);
    }
}
